package ru.yermak.spring;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.stereotype.Component;
import org.springframework.beans.factory.annotation.Autowired;

import java.awt.event.ActionEvent;


/**
 * User: harrier
 * Date: Jan 3, 2009
 * Time: 2:05:34 AM
 */
@Aspect
@Component
public class EventScopeAspect {

    private EventScope eventScope;

    @Autowired
    public void setEventScope(EventScope eventScope) {
        this.eventScope = eventScope;
    }

    @Around("execution( * javax.swing.Action.actionPerformed(java.awt.event.ActionEvent)) " +
            "&& @annotation(ru.yermak.spring.ActionScope) && args(actionEvent)")
    public void inEventScope(ProceedingJoinPoint pjp, ActionEvent actionEvent) throws Throwable {
        eventScope.start(actionEvent);
        pjp.proceed(new Object[]{actionEvent});
        eventScope.end();
    }
}
